/*
 * Observable.c
 *
 *  Created on: 19.01.2013
 *      Author: phru
 */
#include <stdlib.h>
#include "Observable.h"
#include "Observer.h"

/**
 * Update all observers
 */
void update(Observable_t* observable) {
	uint8_t i;
	for (i = 0; i < observable->obsValue; i++) {
		observable->allObs[i]->updateObserver(i);
	}
}

/**
 * Register a new observer
 */
void reg(Observable_t* observable, Observer_t* obs) {
	if ((observable->obsValue + 1) < MAX_OBSERVERS) {
		observable->allObs[observable->obsValue++] = obs;
	}
}

/**
 * Create the observable
 */
Observable_t* createObservable() {
	Observable_t* observable = malloc(sizeof(Observable_t*));
	observable -> reg = reg;
	observable->update = update;
	observable->obsValue = 0;

	return observable;
}
